caef = int(input())
if caef < 999 or caef > 9999:
    print('0')
else:
  caef2 = caef % 10
  cof = (caef // 10) % 10
  cofef = (caef // 100) % 10
  coffeefear = (caef // 1000) % 10
  print(caef2, cof, cofef, coffeefear)
  crafaf1 = coffeefear * 10 + cofef
  crafaf2 = cofef * 10 + cof
  crafaf3 = cof * 10 + caef2
  print(crafaf1, crafaf2, crafaf3)
  abra1 = coffeefear * 100 + cofef * 10 + cof
  abra2 = cofef * 100 + cof * 10 + caef2
  print(abra1, abra2)
  max_prostoe = 0
  count = 0
  for i in range(1, caef + 1):
      if caef % i == 0:
          count += 1
          if count == 2:
              if max_prostoe < caef:
                  max_prostoe = caef
count = 0
for i in range(1, caef2 + 1):
    if caef2 % i == 0:
        count + 1
if count == 2:
    if max_prostoe < caef2:
        max_prostoe = caef2
if count == 2:
    if max_prostoe < cof:
        max_prostoe = cof
if count == 2:
    if max_prostoe < cofef:
        max_prostoe = cofef
if count == 2:
    if max_prostoe < coffeefear:
        max_prostoe = coffeefear
if count == 2:
    if max_prostoe < crafaf1:
        max_prostoe = crafaf1
if count == 2:
    if max_prostoe < crafaf2:
        max_prostoe = crafaf2
if count == 2:
    if max_prostoe < crafaf3:
        max_prostoe = crafaf3
if count == 2:
    if max_prostoe < abra1:
        max_prostoe = abra1
if count == 2:
    if max_prostoe < abra2:
        max_prostoe = abra2
